package com.app.business.web.business;

import com.app.business.model.AzProject;
import com.app.business.model.BzYyDate;
import com.app.business.model.CarLot;
import com.app.business.service.BzYyDateService;
import com.app.system.jpa.PageBean;
import com.app.system.permission.model.DataDict;
import com.app.system.permission.service.DataDictService;
import com.app.system.utils.CollectionUtils;
import com.app.system.utils.ParamUtils;
import com.app.system.utils.WebUtils;
import com.app.system.utils.dataType.BigDecimalUtils;
import com.app.system.utils.dataType.DateUtils;
import com.app.system.utils.dataType.IntegerUtils;
import com.app.system.utils.dataType.StringUtils;
import com.app.system.utils.exception.Precondition;
import com.app.system.utils.exception.Response;
import com.app.system.utils.page.LayUiUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 办证预约控制层
 * Created by szy on 2024/12/30
 */
@Controller
@RequestMapping("/business/bzYyDate/*")
public class BzYyDateController {
    @Autowired
    private BzYyDateService bzYyDateService;
    @Autowired
    private DataDictService dataDictService;

    /**
     * 办证预约状态
     * @param request
     * @param modelMap
     */
    @RequestMapping("bzYyDateList")
    @RequiresPermissions("bzYyDate:bzYyDateList")
    public void bzYyDate(HttpServletRequest request, ModelMap modelMap) {

    }

    /**
     * 加载预约状态
     * @param request
     * @return
     */
    @RequestMapping("loadBzYyDateList")
    @ResponseBody
    @RequiresPermissions("bzYyDate:loadBzYyDateList")
    public Map loadBzYyDateList(HttpServletRequest request) {
        List<Map> listData = Lists.newArrayList();
        PageBean<BzYyDate> bzYyDatePageBean = this.bzYyDateService.bzYyDatePageBean();
        List<BzYyDate> bzYyDateList = bzYyDatePageBean.getDatas();
        Map<String, DataDict> statusMap = this.dataDictService.getMapByParentNameForValue("是否");
        if (!CollectionUtils.isEmpty(bzYyDateList)) {
            Map<String, Object> item = null;
            for (BzYyDate bzYyDate : bzYyDateList) {
                item = null;
                item = Maps.newHashMap();
                item.put("id", bzYyDate.getId());
                item.put("date", DateUtils.dateToStringDefault(bzYyDate.getDate()));
                item.put("statusStr", StringUtils.dataDictShow(statusMap.get(bzYyDate.getStatus().toString())));
                item.put("num", StringUtils.getNotNull(bzYyDate.getNum().toString()));
                item.put("memo", bzYyDate.getMemo());
                item.put("time", bzYyDate.getTime());
                listData.add(item);
            }
        }
        return LayUiUtils.page(bzYyDatePageBean.getTotalCount().intValue(), listData);
    }

    /**
     * 预约时间弹框
     *
     * @param request
     * @param modelMap
     */
    @RequestMapping("bzYyDateForm")
    @RequiresPermissions("bzYyDate:bzYyDateForm")
    public void carLotForm(HttpServletRequest request, ModelMap modelMap) {
        Integer bzYyDateId = ParamUtils.getInt(request, "bzYyDateId", 0);
        BzYyDate bzYyDate = this.bzYyDateService.findOne(bzYyDateId);
        bzYyDate = bzYyDate == null ? new BzYyDate() : bzYyDate;
        modelMap.addAttribute("bzYyDate", bzYyDate);
    }

    /**
     * 办证预约时间保存
     *
     * @param request
     * @return
     */
    @RequestMapping("bzYyDateSave")
    @ResponseBody
    @RequiresPermissions("bzYyDate:bzYyDateSave")
    public Response bzYyDateSave(HttpServletRequest request) {
        Integer bzYyDateId = ParamUtils.getInt(request, "bzYyDateId", 0);
        BzYyDate bzYyDate = bzYyDateService.findOne(bzYyDateId);
        if (bzYyDate == null) {
            bzYyDate = new BzYyDate();
        }
        WebUtils.bind(request, bzYyDate);
        bzYyDateService.save(bzYyDate);
        Response response = new Response();
        response.setCode("0001");
        return response;
    }

}
